﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SpiderStudy.WebSite.Baidu;
using CatUtils.Utils.SpecialUtils.View;
using CatUtils.Utils.Currency.TextUtils;

namespace ArticleContentCreate.ViewManger
{
    public partial class ComicInfo : UserControl
    {
        public ComicInfo()
        {
            InitializeComponent();
            new ViewInfoMemory().InitTextboxSaveInfo(TbArticleLength);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (backgroundWorker1.IsBusy)
                MessageBox.Show("正在扫描中，长时间卡顿请重启程序。");
            else
                backgroundWorker1.RunWorkerAsync();
        }

        private void GetContent(string Tag, RichTextBox ContentBox, Label TipLable)
        {
            new ViewInfoMemory().SaveRichTextboxInfo(ContentBox);
            new ViewAsyncUpdate().LableUpdateTextAsync(TipLable, "正在扫描获取...");
            int ContentLength = TextHelper.StringToInt(TbArticleLength.Text);
            string Content = ContentTool.AutoCreteContent(Tag);
            new ViewInfoMemory().SaveTextboxInfo(TbArticleLength);
            if (ContentLength > 0)
                Content = TextHelper.Substring(Content, 0, ContentLength);
            if (Content != "")
            {
                new ViewAsyncUpdate().RichTextBoxUpdateText(ContentBox, Content);
                new ViewAsyncUpdate().LableUpdateTextAsync(TipLable, "获取完毕！");
            }
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            GetContent(TbTitle.Text, RbContentBox, LbTip);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(RbContentBox.Text);
            label3.Text = "复制成功！" + DateTime.Now.ToString();
        }
    }
}